<style lang="less">
    @import '../../styles/common.less';
    @import '../tables/components/table.less';
</style>

<template>
    <div>
    	<Row >
            <Card>
                <p slot="title" style="height: 32px;">
                	<Row>
                		<Col span="4">{{result.scenesName}}</Col>
                		<Col span="4">测评车辆：<span style="color: red;">{{result.teamName}}</span></Col>
                		<Col span="4">测评线路：<span style="color: red;">{{result.stadiumName}}</span></Col>   
                	</Row>  
                	
           		 </p>  
           		 <Row>
            		 <Col span="4">场景成绩：<span style="color: red;">{{result.scenesResult}}分</span></Col>
            		 <Col span="8">比赛时间：<span >{{result.time}}</span></Col>      
				</Row>
            </Card>           
        </Row>
        <Row class="margin-top-10">
			<Card>				
				<div style="border: 1px solid green;">
				    <Row style="height: 10px;background: green;"></Row>
					<ul style="margin: 10px;">
						<li v-for="item in illegalList" style="padding: 10px;">
							<Row style="height: 100%;">
								<Col span="8">{{item.illegalName}}<span style="color: red;">({{item.illegalScore}}分)</span></Col>
		                		<Col span="8">		                		
		                			<span style="font-size: 17px;" @click="minus(item)"><Icon type="minus-circled" color="#D43F3A"></Icon></span>
									<i style="font-size: 16px;margin: 0 10px;">{{item.illegalCount}}</i> 
									<span style="font-size: 17px;" @click="add(item)"><Icon type="plus-circled" color="#ffbe00"></Icon></span>							
		                		</Col>
		                		<Col span="4"><span style="color: red;">{{item.illegalCount*item.illegalScore}}</span>分</Col>
		                		<Col span="4"><Button @click="save(item)" type="primary" >保存</Button></Col>								
							</Row>								
						</li>
					</ul>
				</div>
				
				<div v-if="manualInterventionList.length>0" style="border: 1px solid green;margin-top: 16px;">
				    <Row style="height: 10px;background: green;"></Row>
					<ul style="margin: 10px;">
						<li v-for="manual in manualInterventionList" style="padding: 10px;">
							<Row style="height: 100%;">
								<Col span="8">{{manual.interveneType === 0?'人工干预':'人工代驾'}}</Col>
		                		<Col span="8">{{manual.startTime}}~{{manual.endTime}}</Col>
		                		<Col span="4"><span style="color: red;">{{manual.deductScore}}</span>分</Col>
		                		<Col span="4"><span style="font-size: 18px;" @click="del(manual)"><Icon type="trash-b" color="#ffbe00"></Icon></span></Col>								
							</Row>					
						</li>
					</ul>
				</div>
			</Card>
		</Row>       
    </div>  
</template>
<script>
import 'jquery';
import tableData from './achievement_detail_data.js';
import canEditTable from '../components/canEditTable.vue';
import {adminId,accessToken,replaceTime,replaceHourTime} from '../components/date.js';
import {baseurl} from '../../libs/util.js';

export default {
    name: 'achievement_edit',
    components: {
        canEditTable
    },
    data () {
        return {
        	result:[],
        	illegalList:[],
        	manualInterventionList : [],          
	       // total: 1,
	        pageSize: 10,
	        scenesResultId : ''
        };
    },
    mounted:function(){
		this.team();
		
	},
    methods: {
    	team : function(){
    		var _self = this;
    		var scenesResultId=this.$route.query.scenesResultId;
    		//alert(scenesResultId+"")
                $.ajax({
                    type: "get",
                    url: baseurl+'/users/' + adminId + "/scenesResults/" + scenesResultId + "?time="+(new Date().getTime()),
                    async: false,                   
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8",
                    beforeSend: function (request) {
                        request.setRequestHeader("accessToken", accessToken);
                    },
                    success: function (data) {
                    	var obj = data.result;
						_self.result = obj;		
						_self.result.time = replaceTime( obj.createTime / 1000 );
						_self.illegalList = obj.illegalResultList;
			            _self.manualInterventionList = obj.manualInterventionList;	
			           for(var i=0; i<_self.manualInterventionList.length; i++){
	                      		var endTime = _self.manualInterventionList[i].endTime;
	                      		_self.manualInterventionList[i].endTime = replaceHourTime(endTime / 1000);
	                      		var startTime = _self.manualInterventionList[i].startTime;
	                      		_self.manualInterventionList[i].startTime = replaceHourTime(startTime / 1000);
	                      		
	                      	}
                    }
        		});
		},
    	add(item){
    		item.illegalCount= item.illegalCount+1;  		
    	},
    	minus(item){
    		if(item.illegalCount>0){
    			item.illegalCount= item.illegalCount-1;  
    		}
    	},
    	save(item){   		
	  		var jsonStr='{"illegalResultId":'+item.illegalResultId+',"illegalCount":'+item.illegalCount+'}';	  		
	  		var th = this;
	  		$.ajax({
	  			type: "PUT",
	  			url:baseurl+'/users/'+adminId+'/illegalResults/'+item.illegalResultId,
	  			data:jsonStr,
	  			async: false,
	  			dataType: 'json',
				contentType: "application/json; charset=utf-8",
	  			beforeSend: function(request) {
					request.setRequestHeader("accessToken", accessToken);
				},
				success: function(data) {
					if(data.code!=1){
						th.$Message.success('保存失败');
					}else{
						th.$Message.success('保存成功');
						th.team();//刷新
					
					}
				}
	  		});
		
    	},
    	 //删除
	  	del(manual){	  	  		
  			var th = this;
  			$.ajax({
	  			type: "DELETE",
	  			url:baseurl+'/users/'+adminId+'/manualInterventions/'+manual.manualInterveneId,
	  			async: false,
	  			dataType: 'json',
				contentType: "application/json; charset=utf-8",
	  			beforeSend: function(request) {
					request.setRequestHeader("accessToken", accessToken);
				},
				success: function(data) {
					if(data.code!=1){						
					}else{
						th.team();						
					}
				}
	  		});
	  	},
        
       
           
    }
    
//  watch: {
//      '$route' () {
//          this.team();
//      }
//  }
     
    
};
</script>


